<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="./plantilla.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    

    <ui:define name="content">
        <f:view>
            <h:form id="form">
                <h1><h:outputText value="List"/></h1>
                <p:dataTable rowKey="#{item.id}" rows="25" selectionMode="single"
                             selection="#{crudcontroller.hardwareActual}" id="lista"
                             rowIndexVar="index" value="#{crudcontroller.listaHardwares}" var="item">
                    <p:ajax event="rowSelect" update=":formeditar:panel" oncomplete="editDialog.show()" /> 
                    <p:column sortBy="#{index+1}">
                        <f:facet name="header">
                            <h:outputText value="N"/>
                        </f:facet>
                        <h:outputText value="#{index+1}"/>
                    </p:column>
                    <p:column sortBy="#{item.descripcion}" filterBy="#{item.descripcion}">
                        <f:facet name="header">
                            <h:outputText value="Descripcion"/>
                        </f:facet>
                        <h:outputText value="#{item.descripcion}"/>
                    </p:column>
                    <p:column>
                        <p:commandButton icon="ui-icon-trash" ajax="false" action="#{crudcontroller.doBorrarHardware(item.id)}"/>
                    </p:column>
                </p:dataTable>
            </h:form>
            <h:form id="formeditar">
                <p:dialog modal="true" hideEffect="explode" showEffect="explode" 
                          header="Editar Hardware" widgetVar="editDialog">
                <h1><h:outputText value="Create/Edit"/></h1>
                <p:panelGrid columns="2" id="panel">
                    <p:outputLabel value="Id:" for="id" />
                    <p:inputText id="id" readonly="true" value="#{crudcontroller.hardwareActual.id}" title="Id" required="true" requiredMessage="The Id field is required."/>
                    <p:outputLabel value="Descripcion:" for="descripcion" />
                    <p:inputText id="descripcion" value="#{crudcontroller.hardwareActual.descripcion}" title="Descripcion" />
                    <p:commandButton value="Guardar" update=":form:lista" 
                                     oncomplete="editDialog.hide();" actionListener="#{crudcontroller.doGuardarHardware()}"/>
                </p:panelGrid>
                </p:dialog>
            </h:form>
        </f:view>


    </ui:define>

</ui:composition>
